#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
#include "tree.h"

using namespace std;
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};


ListNode *newList(int data[], int index, int size)
{
    ListNode *node = NULL;
    if (index == size)
        return node;

    node = new ListNode(data[index]);
    node->next = newList(data, index+1, size);

    return node;
}

Tree *ListToTree(ListNode *&root, int lo, int hi)
{
    if (lo > hi) return NULL;    
    int mid = lo + (hi-lo)/2;
    Tree *left = ListToTree(root, lo, mid-1);
    Tree *node = new Tree(root->val);
    node->left = left;
    root = root->next;
    node->right = ListToTree(root, mid+1, hi);
    return node; 
}


//test on 1337 online judge and pass all the test
int main(int argc, char **argv)
{

    cout << "-----------------Test 1--------------------" << endl;
    int data[] = {1,4,5,6,7};
    ListNode *list1, *list2;
    list1 = newList(data, 0, sizeof(data)/sizeof(int));
    Tree *root = NULL;
    root = ListToTree(list1, 0, sizeof(data)/sizeof(int)-1);
    print_ascii_tree(root);
    cout << endl;

}
